package com.bw.lib_common.utils;

import java.util.Iterator;
import java.util.Objects;

/**
 * @author ykj
 * @date 2025-10-15 17:49
 * @description
 */
public class StringUtils {
    public static String join(final Iterable<?> iterable,final String separator) {
        if (iterable == null){
            return null;
        }
        return join(iterable.iterator(),separator);
    }
    public static String join(final Iterator<?> iterator,final String separator) {
        if (iterator == null){
            return null;
        }
        if (!iterator.hasNext()){
            return "";
        }
        final Object first = iterator.next();
        if (!iterator.hasNext()){
            final String result = objectToString(first);
            return result;
        }
        final StringBuilder buf = new StringBuilder(256);
        if (first != null){
            buf.append(first);
        }
        while (iterator.hasNext()){
            if (separator != null){
                buf.append(separator);
            }
            final  Object obj = iterator.next();
            if (obj != null){
                buf.append(obj);
            }
        }
        return buf.toString();

    }
    private static String objectToString(Object obj) {
        return obj == null ? "" : obj.toString();
    }
    public static boolean isBlank(final CharSequence cs){
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0){
            return true;
        }
        for (int i = 0;i < strLen; i++){
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }
}
